<?php
set_time_limit(0);
error_reporting(E_ALL);
require_once './lib/PHPExcel.php';

$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '序号')
            ->setCellValue('B1', '队员组别')
            ->setCellValue('C1', '队员名称')
            ->setCellValue('D1', '队员号码')
            ->setCellValue('E1', '身高')
            ->setCellValue('F1', '体重')
            ->setCellValue('G1', '擅长位置')
            ->setCellValue('H1', '身份证号码')
            ->setCellValue('I1', '手机号')
            ->setCellValue('J1', '审批状态')
;
include '../c/config.php';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {}

if (isset($_GET['id'])){
    $id=$_GET['id'];
}else{
    exit;
}
  
$query=$mysqli->query("SELECT * FROM `qdui` where id='".$id."' limit 0,1");
$qDui=$query->fetch_assoc();
$qduiName=$qDui['name'];
include '/var/www/chongya/web/thearray.php';
$queryU=$mysqli->query("SELECT * FROM `uinfo` where openid='".$qDui['openid']."' limit 0,1 ");
$getU=$queryU->fetch_assoc();


$index=2;
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.$index, $getU['id'])
->setCellValue('B'.$index, getZuByAge($getU['age']))
->setCellValue('C'.$index, $getU['name'])
->setCellValue('D'.$index, 99)
->setCellValue('E'.$index, $getU['gao'])
->setCellValue('F'.$index, $getU['weight'])
->setCellValue('G'.$index, '')
->setCellValue('H'.$index, $getU['idcard'])
->setCellValue('I'.$index, $getU['phone'].' ')
->setCellValue('J'.$index, '队长')
;

$index++;


$query=$mysqli->query("SELECT * FROM `joinqiu` where qiuid='".$id."'   ");
while ($list=$query->fetch_assoc()){
     
    $queryU=$mysqli->query("SELECT * FROM `uinfo` where openid='".$list['openid']."' limit 0,1 ");
    $getU=$queryU->fetch_assoc();
    
    $shenpi='未审批';
    if(1 == $list['isapply']){
        $shenpi='已审批';
    }
    if(2 == $list['isapply']){
        $shenpi='未同意';
    }
    
    $objPHPExcel->setActiveSheetIndex(0)
    ->setCellValue('A'.$index, $getU['id'])
    ->setCellValue('B'.$index, getZuByAge($getU['age']))
    ->setCellValue('C'.$index, $getU['name'])
    ->setCellValue('D'.$index, $list['qiuhao'])
    ->setCellValue('E'.$index, $getU['gao'])
    ->setCellValue('F'.$index, $getU['weight'])
    ->setCellValue('G'.$index, $weizhiList[$list['weizhi']])
    ->setCellValue('H'.$index, $getU['idcard'])
    ->setCellValue('I'.$index, $getU['phone'].' ')
    ->setCellValue('J'.$index, $shenpi)
    ;
    $index++;
}
 

// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle($qduiName);


// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$qduiName.'.xlsx"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
